import { applyMiddleware, createStore } from 'redux'
import logger from 'redux-logger'
import thunk from 'redux-thunk'
import axios from 'axios'
export const fetchOrderData = () => {
  return dispatch => {
    axios.get('/api/order/list').then(resp => {
      dispatch({ type: 'setOrderData', payload: resp.data.data })
    })
  }
}

const initState = {
  orderData: []
}
const reducer = (prevState = initState, action) => {
  if(action.type === 'setOrderData') {
    return {
      ...prevState,
      orderData: action.payload
    }
  }

  return prevState
}
export const store = createStore(reducer, applyMiddleware(logger, thunk))